GBML manual / Core

every

True once every so many frames, and false the rest of the time: every(60) is true about once a second. Use it to spawn something every two seconds, blink, or tick a counter: if (every(120)) { instance_create(x, y, obj_enemy); }. The second number moves WHEN in the cycle it is true, so two things can fire apart.

Syntax

every(frames, offset = 0) -> bool

Arguments

NameType
framesint
offsetint (can be left out; then it is 0)

Returns

bool

Description

True once every so many frames, and false the rest of the time. every(60) is true about once a second, because the console shows about 60 frames a second.

Use it to spawn something every two seconds, to blink, or to tick a counter, without setting up a timer of your own.

Example

if (every(120)) {
    x += 8;
}

Every two seconds the walker takes a step to the right of 8 pixels.

Making two things fire apart

The second number moves when in the cycle it is true. Every object that asks every(60) gets true on the same frame. Ask every(60, 30) in one of them, and it fires half a second after the others.

var tick = every(60);
var tock = every(60, 30);

The small print

Cost

One remainder sum.

On the GBA

It reads the game's own frame counter (the one game_frame gives), so it needs no timer of yours and no alarm. That also means every object asking every(60) gets true on the SAME frame; ask every(60, 30) in one of them and it fires half a second later than the other. It keeps counting while the game is paused, but Step events do not run then, so a paused game does not fire it. 60 frames is about a second. frames of 0 or less is never true. Because the frame counter is a whole number it stays right however long the console stays on. Nothing is stored anywhere: it is one remainder sum.

See also: game_framewavetweenalarm